package com.kc.web.controller.business;

import com.kc.business.domain.BizCommentReply;
import com.kc.business.service.IBizCommentReplyService;
import com.kc.common.annotation.Log;
import com.kc.common.core.controller.BaseController;
import com.kc.common.core.domain.AjaxResult;
import com.kc.common.core.page.TableDataInfo;
import com.kc.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 评论回复service
 */
@RestController
@RequestMapping("/business/commentReply")
public class BizCommentReplyController extends BaseController {
    @Autowired
    private IBizCommentReplyService commentReplyService;
    /**
     * 评论回复列表
     * @param id
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:commentReply:list')")
    @GetMapping("/list")
    public TableDataInfo list(Integer id) {
        List<BizCommentReply> list = new ArrayList<>();
        if(id == null){
            return getDataTable(list);
        }
        BizCommentReply commentReply = new BizCommentReply();
        commentReply.setCommentId(id);
        startPage();
        list = commentReplyService.getList(commentReply);
        return getDataTable(list);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:commentReply:remove')")
    @Log(title = "评论回复管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Integer id){
        BizCommentReply commentReply = new BizCommentReply();
        commentReply.setId(id);
        commentReply.setIsDeleted(1);
        commentReply.setStatus(-1);
        return toAjax(commentReplyService.remove(commentReply));
    }
}
